package com.zzptc.tkfate;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.google.gson.Gson;
import com.zzptc.tkfate.entity.Students;

public class MainActivity2 extends AppCompatActivity {
    private static final String TAG = "MainActivity2";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Gson gson=new Gson();
        //language=JSON
        String str="{\n" +
                "  \"code\": 1,\n" +
                "  \"date\": [{\n" +
                "    \"stu_id\": 1,\n" +
                "    \"stu_name\": \"世道\",\n" +
                "    \"stu_age\": 20\n" +
                "  },{\n" +
                "    \"stu_id\": 2,\n" +
                "    \"stu_name\": \"士郎\",\n" +
                "    \"stu_age\": 20\n" +
                "  }]\n" +
                "}";
        Students students = gson.fromJson(str, Students.class);
        Log.d(TAG, "onCreate: "+students.getData().get(0).getStu_name());
        Log.d(TAG,"onCreate: "+gson.toJson(students));
    }
}
